package com.xnyzc.lhy.mis.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xnyzc.lhy.mis.entity.order.OaCOrderPersonal;
import com.xnyzc.lhy.mis.entity.result.cms.driver.CmsOaDVehicleGpsRes;
import com.xnyzc.lhy.mis.entity.result.cms.order.CmsOadCharterOrderDetailRes;
import com.xnyzc.lhy.mis.entity.result.order.OaCOrderAssignStatusRes;
import com.xnyzc.lhy.resource.entity.worksheet.param.WorksheetgetOrderPersonalListParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 自费叫车订单 Mapper 接口
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-22
 */
public interface OaCOrderPersonalMapper extends BaseMapper<OaCOrderPersonal> {

    /**
     * 依据手机号查询订单列表
     * @param param 对象
     * @return
     */
    List<OaCOrderPersonal> selectListLimit(WorksheetgetOrderPersonalListParam param);

    /**
     * 依据手机号查询订单列表
     * @param param 用户ID
     * @return
     */
    Integer selectListLimitTotal(WorksheetgetOrderPersonalListParam param);

    /**
     * 依据手机号查询订单列表
     * @param param 对象
     * @return
     */
    List<OaCOrderPersonal> selectDriverListLimit(WorksheetgetOrderPersonalListParam param);

    /**
     * 依据手机号查询订单列表
     * @param param 手机号
     * @return
     */
    Integer selectDriverListLimitTotal(WorksheetgetOrderPersonalListParam param);

    List<CmsOaDVehicleGpsRes> selectDriverPositionList();

    CmsOaDVehicleGpsRes selectDriverPositionByDriverId(@Param("driverId") Long driverId);

    List<OaCOrderAssignStatusRes> getAssignCountsByVehicleType(String cityCode, String date);

    @Select("SELECT\n" +
            "oa_c_order_personal.personal_id,\n" +
            "oa_c_order_personal.order_no,\n" +
            "oa_c_order_personal.passenger_phone,\n" +
            "oa_c_order_personal.passenger_name,\n" +
            "oa_c_order_personal.appointment,\n" +
            "oa_c_order_personal.vehicle_type,\n" +
            "oa_c_order_personal.start_address,\n" +
            "oa_c_order_personal.end_address,\n" +
            "oa_c_order_personal.duration_time,\n" +
            "oa_c_order_personal.milage_distance,\n" +
            "oa_c_order_personal.total_fee, \n" +
            "odc.dayCount,\n" +
            "date_format( oa_c_order_personal.create_time, '%Y-%m-%d %H:%i:%s' ) AS create_time_str\n" +
            "FROM\n" +
            "oa_c_order_personal\n" +
            "LEFT JOIN ( SELECT order_no, count( 1 ) AS dayCount FROM oa_d_order_chartered_detail as ocd GROUP BY ocd.order_no ) AS odc ON odc.order_no = oa_c_order_personal.order_no \n" +
            "WHERE\n" +
            "oa_c_order_personal.deleted = 0 \n" +
            "AND oa_c_order_personal.order_no = #{orderNo}")
    CmsOadCharterOrderDetailRes selectOaCorderDetailByOrderNo(@Param("orderNo") String orderNo);
}
